package rai.blo;

import org.apache.log4j.Logger;

import rai.dto.LoginUserDTO;
import rai.dao.LoginDAO;

/**
 * Process business logic for Login Form.
 *
 * @author Tien
 * */
public class LoginBLO {
    /** log property. */
    private static Logger log = Logger.getLogger("LoginBLO");

    /** DAO property. */
    private LoginDAO loginDAO = new LoginDAO();

    /**
     * Check whenever user is valid.
     *
     * @param name
     * @param pass
     * @return res
     */
    public final boolean isValidUser(final String name, final String pass) {
        log.debug("isValidUser.start");
        boolean res = true;
        LoginUserDTO data = loginDAO.getUser(name, pass);
        
        if (data == null) {
            res = false;
        }
        log.debug("isValidUser.end");
        
        return res;
    }

    /**
     * get Role of User.
     *
     * @param ID
     * @param name
     * @param pass
     * @return Role data
     */
    public String readRole(String name, String pass) {
        log.debug("readRole.start");
        LoginUserDTO data = loginDAO.getUser(name, pass);
        log.debug("readrole.end");
        return data.getRole();
    }
    /**
     * Get the ID of User.
     * @param name
     * @param pass
     * @return data.getId()
     */
    public int readID(String name, String pass) {
        log.debug("readID.start");
        LoginUserDTO data = loginDAO.getUser(name, pass);
        log.debug("readID.end");
        return data.getId();
    }
}
